
# REQUIRES: Data/Roper Data.csv

# NOTE: Uses code from Stargazer Package Updates.R instead of the published version of Stargazer. See readme.txt.

################# Dependencies #################
# source("Load Packages.R")
# source("Analysis - Roper/Cleaning.R")

################# Create Polling Organization Variables #################

#38
roper$CBS <- ifelse(roper$Pollingorg=="CBS News",1,0)
roper$CBS <- ifelse(roper$Pollingorg=="CBS News; New York Times",1,roper$CBS)

#37
roper$Gallup <- ifelse(roper$Pollingorg=="Gallup Organization",1,0)
roper$Gallup <- ifelse(roper$Pollingorg=="Gallup",1,roper$Gallup)

#26
roper$ORC <- ifelse(roper$Pollingorg=="ORC",1,0)
roper$ORC <- ifelse(roper$Pollingorg=="Opinion Research Corporation",1,roper$ORC)

#24
roper$Princeton <- ifelse(roper$Pollingorg=="Princeton Survey Research Associates International",1,0)

#19
roper$Hart <- ifelse(roper$Pollingorg=="Hart-Teeter Research Companies",1,0)
roper$Hart <- ifelse(roper$Pollingorg=="Hart and McInturff Research Companies",1,roper$Hart)
roper$Hart <- ifelse(roper$Pollingorg=="Hart and Poll # 2006-6061: Congress/Health Care/Economy/Immigration/Middle East/Iraq Research Companies",1,roper$Hart)
roper$Hart <- ifelse(roper$Pollingorg=="Hart/Newhouse Research Companies",1,roper$Hart)
roper$Hart <- ifelse(roper$Pollingorg=="Hart Research Associates; Public Opinion Strategies",1,roper$Hart)

#18
roper$NYT <- ifelse(roper$Pollingorg=="CBS News; New York Times",1,0)
roper$NYT <- ifelse(roper$Pollingorg=="New York Times",1,roper$NYT)

#17
roper$TNS <- ifelse(roper$Pollingorg=="TNS Intersearch",1,0)

#14
roper$LouisHarris <- ifelse(roper$Pollingorg=="Louis Harris & Associates",1,0)
roper$LouisHarris <- ifelse(roper$Pollingorg=="Louis Harris & Associates Poll",1,roper$LouisHarris)
roper$LouisHarris <- ifelse(roper$Pollingorg=="Harris Interactive",1,roper$LouisHarris)

#13
roper$ABC <- ifelse(roper$Pollingorg=="ABC News; Washington Post",1,0)
roper$ABC <- ifelse(roper$Pollingorg=="ABC News",1,roper$ABC)

#10
roper$WashingtonPost <- ifelse(roper$Pollingorg=="ABC News; Washington Post",1,0)

#10
roper$LATimes <- ifelse(roper$Pollingorg=="Los Angeles Times",1,0)



#6
roper$Other <- ifelse(roper$Pollingorg=="Knowledge Networks",1,0)

#5
roper$Other <- ifelse(roper$Pollingorg=="Schulman, Ronca & Bucuvalas, Inc.",1,roper$Other)
roper$Other <- ifelse(roper$Pollingorg=="Abt SRBI, Inc. (Schulman, Ronca, & Bucuvalas, Inc.)",1,roper$Other)
roper$Other <- ifelse(roper$Pollingorg=="Langer Research Associates; Abt SRBI, Inc.",1,roper$Other)
roper$Other <- ifelse(roper$Pollingorg=="Langer Research Associates; Capital Insight; Abt SRBI, Inc.",1,roper$Other)
roper$Other <- ifelse(roper$Pollingorg=="Abt Associates",1,roper$Other)

#5
roper$Other <- ifelse(roper$Pollingorg=="National Opinion Research Center (NORC)",1,roper$Other)
roper$Other <- ifelse(roper$Pollingorg=="National Opinion Research Center; Stanford University",1,roper$Other)

#3
roper$Other <- ifelse(roper$Pollingorg=="Gfk Roper Public Affairs & Media",1,roper$Other)
roper$Other <- ifelse(roper$Pollingorg=="GfK Roper Public Affairs & Corporate Communications",1,roper$Other)

#4
roper$Other <- ifelse(roper$Pollingorg=="National Opinion Research Center; Stanford University",1,roper$Other)

#4
roper$Other <- ifelse(roper$Pollingorg=="Ipsos",1,roper$Other)

#3
roper$Other <- ifelse(roper$Pollingorg=="Quinnipiac University Polling Institute",1,roper$Other)

#2
roper$Other <- ifelse(roper$Pollingorg=="Langer Research Associates; Abt SRBI, Inc.",1,roper$Other)
roper$Other <- ifelse(roper$Pollingorg=="Langer Research Associates; Capital Insight; Abt SRBI, Inc.",1,roper$Other)

#2
roper$Other <- ifelse(roper$Pollingorg=="Social Science Research Solutions (SSRS)",1,roper$Other)
roper$Other <- ifelse(roper$Pollingorg=="SSRS",1,roper$Other)

#2
roper$Other <- ifelse(roper$Pollingorg=="Hart Research Associates; Public Opinion Strategies",1,roper$Other)

#2
roper$Other <- ifelse(roper$Pollingorg=="Marist College Institute for Public Opinion",1,roper$Other)

#1
roper$Other <- ifelse(roper$Pollingorg=="Chilton Research Services",1,roper$Other)

#1
roper$Other <- ifelse(roper$Pollingorg=="Latino Decisions",1,roper$Other)

#1
roper$Other <- ifelse(roper$Pollingorg=="Selzer & Co.",1,roper$Other)

#1
roper$Other <- ifelse(roper$Pollingorg=="Langer Research Associates; Capital Insight; Abt SRBI, Inc.",1,roper$Other)

#1
roper$Other <- ifelse(roper$Pollingorg=="Monmouth University Polling Institute",1,roper$Other)

################# Table S6 - Predictors of US Public Support for Withdrawal, 1946-2021 #################

# With question and situation features, mode fixed effects
OLS_m <- lm(percwithdraw ~  bEnemyVictory + bDeescalationOption + bOnesidedquestion 
             + logcas + FPR + Vietnam + Gulf_War + Afghanistan + Iraq + Method, 
             data = roper)

# With question and situation features, house fixed effects
OLS_h <- lm(percwithdraw ~  bEnemyVictory + bDeescalationOption + bOnesidedquestion 
             + logcas + FPR + Vietnam + Gulf_War + Afghanistan + Iraq 
             + CBS + Gallup + ORC + Princeton + Hart + NYT + TNS + LouisHarris + ABC + WashingtonPost + LATimes, 
             data = roper)

output <- stargazer(OLS_m, OLS_h,  title="Table A6: Replication of Observational Results with Dummy Variables for Mode and House Fixed Effects",
                    align=TRUE, dep.var.labels=c(""), dep.var.caption="",
                    column.labels=c(" ","",""),
                    digits = 3, digits.extra = 0,
                    notes = "P-value shown in parentheses below coefficient", 
                    notes.append = FALSE,
                    report = "vc*p",
                    covariate.labels=c("Enemy Victory Framing", "Troop Reduction Option", "One-sided Question",
                                       "Log Cumulative Casualties", "Foreign Policy Restraint",
                                       "Vietnam", "Gulf War", "Afghanistan", "Iraq", 
                                       "Method: Phone", "Method: Web-Based Survey",
                                       "CBS", "Gallup", "ORC", "Princeton", "Hart", "NYT", "TNS", "Louis Harris", "ABC", "Washington Post", "LA Times", "Constant"),
                    omit.stat=c("LL","ser","f","adj.rsq"), no.space=TRUE, notes.align="c", out = "Plots/Table S6 - Predictors of US Public Support for Withdrawal, 1946-2021_R.html")

webshot("Plots/Table S6 - Predictors of US Public Support for Withdrawal, 1946-2021_R.html", "Plots/Table S6 - Predictors of US Public Support for Withdrawal, 1946-2021_R.png", zoom=5, vwidth=580, vheight=600)
# Note: Add the independent variable groups in Word and remove "_R" from the file name
# webshot("Plots/Table S2 - Predictors of US Public Support for Withdrawal, 1946-2021.html", "Plots/Table S2 - Predictors of US Public Support for Withdrawal, 1946-2021.png", zoom=5, vwidth=475, vheight=580)

rm(OLS_m, OLS_h, output)
